<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{.Title}}</title>
    <link href="/static/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/libs/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
    <link href="/static/css/app.css" rel="stylesheet">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/">
                <i class="bi bi-database"></i>
                PGM - PostgreSQL管理平台
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/">
                            <i class="bi bi-house"></i>
                            首页
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/api/tables">
                            <i class="bi bi-table"></i>
                            API文档
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="row">
            <div class="col-md-12">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h1 class="h3">
                        <i class="bi bi-database"></i>
                        数据库表管理
                    </h1>
                    <button class="btn btn-primary" onclick="refreshTables()">
                        <i class="bi bi-arrow-clockwise"></i>
                        刷新
                    </button>
                </div>

                {{if .Tables}}
                <div class="row">
                    {{range .Tables}}
                    <div class="col-md-6 col-lg-4 mb-3">
                        <div class="card h-100">
                            <div class="card-body">
                                <h5 class="card-title">
                                    <i class="bi bi-table"></i>
                                    {{.Name}}
                                </h5>
                                <p class="card-text text-muted">
                                    {{if .Comment}}
                                        {{.Comment}}
                                    {{else}}
                                        数据表: {{.Name}}
                                    {{end}}
                                </p>
                                <div class="d-flex justify-content-between align-items-center">
                                    <small class="text-muted">
                                        列数: {{len .Columns}}
                                        {{if .PrimaryKeys}}| 主键: {{index .PrimaryKeys 0}}{{end}}
                                    </small>
                                </div>
                            </div>
                            <div class="card-footer bg-transparent">
                                <div class="btn-group w-100" role="group">
                                    <a href="/table/{{.Name}}" class="btn btn-outline-primary">
                                        <i class="bi bi-eye"></i>
                                        查看
                                    </a>
                                    <a href="/table/{{.Name}}/create" class="btn btn-outline-success">
                                        <i class="bi bi-plus"></i>
                                        新增
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {{end}}
                </div>
                {{else}}
                <div class="alert alert-info text-center">
                    <i class="bi bi-info-circle"></i>
                    暂无数据表，请检查数据库连接或创建一些表。
                </div>
                {{end}}
            </div>
        </div>
    </div>

    <footer class="bg-light py-4 mt-5">
        <div class="container text-center">
            <p class="text-muted mb-0">
                <i class="bi bi-heart-fill text-danger"></i>
                PGM - PostgreSQL管理平台 | 动态数据库管理工具
            </p>
        </div>
    </footer>

    <script src="/static/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/static/js/app.js"></script>
    
    <script>
    function refreshTables() {
        window.location.reload();
    }
    </script>
</body>
</html>